/**
 * Project Name:fire-industry-DM-center
 * File Name:SwaggerConfig.java
 * Package Name:com.firestone.config.swagger
 * Date:2018年3月8日下午5:32:07
 *
*/

package com.firestone.config.swagger;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Description: TODO(swagger2配置--用于自动生产接口文档)
 * @author CAIYJ
 * @date 2018年3月8日 下午5:32:07
 */
@Configuration
@EnableSwagger2
@Profile({ "dev", "test" })
public class SwaggerConfig extends WebMvcConfigurationSupport {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.firestone.web"))
                .paths(PathSelectors.any()).build()
                .globalOperationParameters(parameter());
    }

    /**
     * 全局参数
     * 
     * @return
     */
    private List<Parameter> parameter() {
        List<Parameter> params = new ArrayList<>();
        params.add(new ParameterBuilder().name("token").description("用户token")
                .modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());
        return params;

    }

    @SuppressWarnings("deprecation")
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("产业地图生产中心")
                .description("DM层数据管理，配置管理等管理")
                .termsOfServiceUrl("http://gov.hsmap.com").contact("火石创造")
                .version("1.0").build();
    }
}
